﻿using System.Collections.Generic;

	public delegate void EventDelegate(object[] args = null);
	/// <summary>
	/// 事件管理器
	/// </summary>
	public class BaseEventMgr<T> {
		/// <summary>
		/// 已注册事件哈希表
		/// </summary>
		private Dictionary<T, EventDelegate> events = new Dictionary<T, EventDelegate>();

		/// <summary>
		/// 事件注册
		/// </summary>
		public void RegistEvent(T key, EventDelegate value) {
			if (events.ContainsKey(key)) {
				events[key] += value;
			} else {
				events.Add(key, value);
			}
		}

		/// <summary>
		/// 事件触发
		/// </summary>
		public void RaiseEvent(T key, object[] args = null) {
			if (events.ContainsKey(key)) {
				events[key](args);
			}
		}

		/// <summary>
		/// 事件解除
		/// </summary>
		public void RemoveEvent(T key, EventDelegate value) {
			if (events.ContainsKey(key))
			{
				events[key] -= value;
			}
		}

		public void Clear()
		{
			events.Clear();
		}
	}

//public class EventFunc
//{
////	private readonly int _priority;
////
////	public int Priority
////	{
////		get { return _priority; }
////	}
//
//	private readonly EventDelegate func;
//
//	public EventFunc(EventDelegate func, int priority = 0)
//	{
//		this.func = func;
////		this._priority = _priority;
//	}
//
//	public void Execute(object[] args = null)
//	{
//		if (func != null)
//		{
//			func(args);
//		}
//		else
//		{
//			Debug.LogError("Func is null");
//		}
//	}
//}
